Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
library(lubridate)library(tsibble)
Registered S3 method overwritten by 'tsibble':
method from
as_tibble.grouped_df dplyr
Attaching package: 'tsibble'
The following object is masked from 'package:zoo':
index
The following object is masked from 'package:lubridate':
interval
The following objects are masked from 'package:base':
intersect, setdiff, union
library(feasts)
Loading required package: fabletools
Attaching package: 'fabletools'
The following object is masked from 'package:yardstick':
accuracy
The following object is masked from 'package:parsnip':
null_model
The following objects are masked from 'package:infer':
generate, hypothesize
library(plotly)
Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
# Example: Cache la Poudre River at Mouth (USGS site 06752260)poudre_flow <-readNWISdv(siteNumber ="06752260", # Download data from USGS for site 06752260parameterCd ="00060", # Parameter code 00060 = discharge in cfs)startDate ="2013-01-01", # Set the start dateendDate ="2023-12-31") |># Set the end daterenameNWISColumns() |># Rename columns to standard names (e.g., "Flow", "Date")mutate(Date =yearmonth(Date)) |># Convert daily Date values into a year-month format (e.g., "2023 Jan")group_by(Date) |># Group the data by the new monthly Datesummarise(Flow =mean(Flow)) # Calculate the average daily flow for each month
# A tsibble: 6 x 2 [1M]
Date Flow
<mth> <dbl>
1 2013 Jan 18.1
2 2013 Feb 18.0
3 2013 Mar 8.21
4 2013 Apr 5.94
5 2013 May 333.
6 2013 Jun 300.
Plotting the time series
flow_plot <-ggplot(poudre_flow, aes(x = Date, y = Flow)) +geom_line(color ="darkblue") +labs(title ="Cache la Poudre River Streamflow",x ="Date", y ="Flow (cfs)") +theme_minimal()ggplotly(flow_plot)
Subseries
gg_subseries(poud_tbl) +labs(title ="Monthly Poudre River Streamflow Patterns", y ="Flow", x ="Year") +theme_minimal()
Plot variable not specified, automatically selected `y = Flow`
I notice that streamflow is relatively low October through March consistenetly throughout the 10 year period. May and June have significantly higher streamflows than the rest of the months while April, July, August, and September have slightly higher flows than October through March. I also see that there was abnormally high streamflows in September of 2014 which may indicate a flood. Seasons are not specifically defined in this plot, however streamflow is divided up by month. We can assume that there is a season of low flows (September-March) and a season of high flows (April-August). The subseries represents how streamflows during January behaves across the ten year period. This allows us to compare how the months behave over the years.
The seasonal component is most appropriate for Poudre River streamflow data. The plot shows various patterns in flows over a ten year period. The seasonal window depicts streamflow patterns throughout the months of the year, most likely related to snowmelt patterns. Seasonal streamflow has stayed relatively the same in the last ten years. The trend window depicts streamflow levels over the ten year period, most likely related to long term influences such as climate change. Trend streamflows have decreased in the last ten years.